package com.jxd.project.absence.controller;

import com.jxd.project.absence.dto.AbsenceDto;
import com.jxd.project.absence.dto.QueryFormDto;
import com.jxd.project.absence.model.AbsenceType;
import com.jxd.project.absence.model.Dept;
import com.jxd.project.absence.model.PreMenu;
import com.jxd.project.absence.service.*;
import com.jxd.project.absence.vo.EmpInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName GetInfoController
 * @Description TODO
 * @Author 李杨
 * @Date 2025/10/8 13:53
 * @Version 1.0
 */
@RestController
public class GetInfoController {
    @Autowired
    private IAbsenceTypeService absenceTypeService;
    @Autowired
    private IAbsenceService absenceService;
    @Autowired
    private IEmpService empService;
    @Autowired
    private IDicService dicService;
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IPreMenuService menuService;

    @RequestMapping("/getAbsenceType")
    public Map<String,Object> getAbsenceType(){
        List<AbsenceType> list = absenceTypeService.list();
        Map<String,Object> res = new HashMap<>();
        if (list.isEmpty()){
            res.put("code",500);
            res.put("msg","服务器错误");
        } else {
            res.put("code",200);
            res.put("data",list);
        }
        return res;
    }

    @RequestMapping("/getAbsenceType1")
    public Map<String,Object> getAbsenceType1(){
        Map<String,Object> res = new HashMap<>();
        res.put("msg","success");
        res.put("data", dicService.getAbsenceType());
        return res;
    }

    @RequestMapping("/getYearDays")
    public int getYearDays(@RequestParam int years){
        return dicService.getYearDays(years);
    }

    @RequestMapping("/getAbsence")
    public Map<String,Object> getAbsence(@RequestBody QueryFormDto queryForm){
        Map<String,Object> res = new HashMap<>();
        List<AbsenceDto> list = absenceService.getAbsence(queryForm);
        res.put("code",200);
        res.put("data",list);
        return res;
    }

    @RequestMapping("/getEmpInfo")
    public Map<String,Object> getEmpInfo(@RequestParam int empno){
        Map<String,Object> res = new HashMap<>();
        EmpInfo empInfo = empService.getEmpInfo(empno);
        if (empInfo == null){
            res.put("code",500);
            res.put("msg","服务器错误");
        } else {
            res.put("code",200);
            res.put("data",empInfo);
        }
        return res;
    }
    @RequestMapping("/getOneAbsence")
    public Map<String,Object> getOneAbsence(@RequestParam int id){
        Map<String,String> map = absenceService.getOneById(id);
        Map<String,Object> res = new HashMap<>();

        res.put("code",200);
        res.put("data",map);

        return res;
    }

    @RequestMapping("/getDeptByNull")
    public List<Dept> getDept(){
        return deptService.list();
    }

    @RequestMapping("/getMenus")
    public List<PreMenu> getMenus(@RequestParam String userid){

        return menuService.getMenu(userid);
    }

    @RequestMapping("/getMyToDo")
    public int getMyToDo(@RequestParam String userid){
        return absenceService.getMyToDo(userid);
    }
}
